//  -----------------------------------------------------------------------------------------------//
//   This file is part of SvnExternalUpdater                                                               //
//   Copyright (C)2008 Romain Verdier ( romain@codingly.com )                                      //
//                                                                                                 //
//   This program is free software; you can redistribute it and/or modify it under the terms       //
//   of the GNU General Public License as published by the Free Software Foundation; either        //
//   version 2 of the License, or (at your option) any later version. This program is distributed  //
//   in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied        //
//   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public  //
//   License for more details.                                                                     //
//                                                                                                 //
//   You should have received a copy of the GNU General Public License along with this program; if //
//   not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. or  //
//   see http://www.fsf.org/licensing/licenses/gpl.html                                            //
//  -----------------------------------------------------------------------------------------------//
using System;
using System.Windows.Forms;
using Codingly.SvnExternalUpdater.Presenters;

namespace Codingly.SvnExternalUpdater.Views
{
	public partial class ConfigurationView : Form, IConfigurationView
	{
		private ConfigurationPresenter presenter;
		private string rootFolder;

		public ConfigurationView()
		{
			InitializeComponent();
			this.rootFolder = Environment.CurrentDirectory;
		}

		private void buttonAdd_Click(object sender, EventArgs e)
		{
			using (var dialog = new FolderBrowserDialog())
			{
				dialog.SelectedPath = this.rootFolder;
				dialog.ShowNewFolderButton = false;
				dialog.Description = "Select a versioned project folder to monitor :";
				if (dialog.ShowDialog() == DialogResult.OK)
				{
					this.presenter.AddProject(dialog.SelectedPath);
					this.rootFolder = dialog.SelectedPath;
				}
			}
		}

		private void buttonRemove_Click(object sender, EventArgs e)
		{
			int index = this.listBoxProjects.SelectedIndex;
			if (this.listBoxProjects.SelectedIndex != -1)
			{
				this.presenter.RemoveProject((string) this.listBoxProjects.Items[index]);
			}
		}

		#region IConfigurationView Members

		public ConfigurationPresenter Presenter
		{
			get { return this.presenter; }
			set { this.presenter = value; }
		}

		public void AddProject(string project)
		{
			this.listBoxProjects.Items.Add(project);
		}

		public void RemoveProject(string project)
		{
			this.listBoxProjects.Items.Remove(project);
		}

		public bool ShowModal()
		{
			return ShowDialog() == DialogResult.OK;
		}

		#endregion
	}
}